/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.business.account.core.service.processor.active;

import cn.hutool.core.lang.Assert;
import info.peigen.hotpot.business.account.core.domain.account.Account;
import info.peigen.hotpot.business.account.core.service.processor.base.AbstractAccountServiceProcessor;
import info.peigen.hotpot.business.account.facade.enums.AccountStatus;
import info.peigen.hotpot.business.account.facade.order.freeze.UnfreezeAccountOrder;
import info.peigen.hotpot.common.core.result.ResultCode;
import info.peigen.hotpot.common.service.base.exception.BusinessException;
import info.peigen.hotpot.common.service.base.processor.Processor;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Component;

/**
 * <b>(ActiveAccountForUnfreezeProcessor)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2022/5/26
 */
@Slf4j
@Component
public class ActiveAccountForUnfreezeProcessor extends AbstractAccountServiceProcessor implements Processor {
    @Override
    public Integer level() {
        return 11;
    }

    @Override
    public void execute(ProcessorServiceContext serviceContext) {
        String  accountId = ((UnfreezeAccountOrder) serviceContext.getOrder()).getAccountId();
        Account account   = accountRepository.lock(accountId);
        Assert.notNull(account, () -> new BusinessException(ResultCode.FAILURE, "未能锁定账户[accountId=" + accountId + "]"));

        if (account.getStatus() != AccountStatus.Freeze) {
            log.info("该账户并未锁定[accountId={}]", accountId);
        }
        serviceContext.setDomain(account);
    }
}
